package com.structure.algorithm;

/**
 * 不使用加减乘除做四则运算
 * 异或相异为1，相同为0，算加法
 * 与相异为0，相同为1，然后通过左移算进位
 * Created by sucre on 2015/11/9.
 */
public class NumberOperation {
    //通过逻辑运算来进行加减运算
    public static int add(int one,int two){
        int sum,carry;
        do {
            sum = one^two;
            carry = (one & two)<<1;
            one = sum;
            two = carry;
        }while (two !=0);
        return one;
    }
    public static void main(String[] args){
        System.out.print(add(1,1));
    }
}
